//
//  TopicListViewController.m
//  Leisure
//
//  Created by Alex on 16/6/30.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "TopicListViewController.h"

@interface TopicListViewController ()<UIWebViewDelegate>
@property (nonatomic,strong)UIWebView *webview;

@end

@implementation TopicListViewController

- (UIWebView *)webview {
    
    if (!_webview) {
        _webview = [[UIWebView alloc]initWithFrame:self.view.frame];
        _webview.delegate = self;
        _webview.scrollView.bounces = NO;
        _webview.scrollView.bouncesZoom = NO;
    }
    return _webview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.webview];
    [RequestManager fecthDataWithUrl:kTopicInfoUrl parameter:@{@"contentid":self.contentID} mehtod:@"POST" compelet:^(NSData *data) {

        NSDictionary *bigdic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        
        [self.webview loadHTMLString:bigdic[@"data"][@"postsinfo"][@"html"] baseURL:nil];

    } updateUI:^{

    }];
  //  [self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];
    
 //   self.view.backgroundColor = [UIColor brownColor];
    
}

#pragma mark ----------WebViewDelegate-----------
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString *js = @"function imgAutoFit() { \
    var imgs = document.getElementsByTagName('img'); \
    for (var i = 0; i < imgs.length; ++i) {\
    var img = imgs[i];   \
    img.style.maxWidth = %f;   \
    } \
    }";
    js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
    
    [webView stringByEvaluatingJavaScriptFromString:js];
    [webView stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}



@end
